//
//  HYBCardScaleViewController.m
//  CollectionViewDemos
//
//  Created by huangyibiao on 16/3/27.
//  Copyright © 2016年 huangyibiao. All rights reserved.
//

#import "HYBCardScaleViewController.h"
#import "HYBCardScaleFlowLayout.h"
#import "HYBCardCollectionViewCell.h"


static NSString *cellIdentifier = @"CellIdentifier";

@interface HYBCardScaleViewController () <UICollectionViewDataSource>
{

    CGFloat speed ;
    CGFloat allCount;
    UICollectionView *_collectionView;
}
@end

@implementation HYBCardScaleViewController

- (void)viewDidLoad {
  [super viewDidLoad];
    speed=5;
    allCount=0.0;
  CGRect viewCGRect= CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64) ;
  HYBCardScaleFlowLayout *layout = [[HYBCardScaleFlowLayout alloc] init];
  
   _collectionView = [[UICollectionView alloc] initWithFrame:viewCGRect collectionViewLayout:layout];
  [self.view addSubview:_collectionView];
  [_collectionView registerClass:[HYBCardCollectionViewCell class] forCellWithReuseIdentifier:cellIdentifier];
  _collectionView.dataSource = self;
  self.view.backgroundColor = [UIColor whiteColor];
  _collectionView.backgroundColor = [UIColor purpleColor];
    
    [NSTimer scheduledTimerWithTimeInterval:0.001 target:self
                                   selector:@selector(timeBgain:) userInfo:nil repeats:YES];
    
}
-(void)timeBgain:(id)sender
{
    allCount+=speed;
    
    [_collectionView setContentOffset:CGPointMake(allCount, 0)];
    if (allCount<=0||allCount>=(_collectionView.contentSize.width-_collectionView.frame.size.width))
    {
        speed=-speed;
    }

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  return 5;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  return  1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  HYBCardCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier
                                                                              forIndexPath:indexPath];
  [cell configWithImage:[NSString stringWithFormat:@"img%ld.jpg", indexPath.item + 1]];
  
  return cell;
}

@end
